﻿Imports Cognex.VisionPro
Imports System.Net.Sockets
Imports Cognex.VisionPro.ToolBlock
Imports CommonDLL.Common
Imports OPC_Class

Module GlobalVar
    Public PublicHikScanConfig As New HikScanConfig

    Public Class HikScanConfig
        Public ScanIP As String = "192.168.1.96"
        Public ScanProt As String = "9000"
        Public ScanStart As String = "T"
        Public ScanEnd As String = "U"
        Public ScanWhileTime As String = "200"
        Public ScanWhileEnable As String = "False"
        Public ScanEnable As String = "False"
    End Class

    Public Structure offset
        Public x As Double  'X偏移
        Public y As Double  'Y偏移
        Public r As Double '角度偏移
        Public IsPass As Boolean '是否OK
        Public ErrCode As Integer '如果有错误，返回错误代码，如果没有则是0
    End Structure

    Public Structure Point_Para
        Public torque As Double '扭力
        Public angle As Double  '角度
        Public feeder As Integer '供料器
        Public diable As Boolean '是否禁用
        'Public Round_num As Boolean '圈数检测
    End Structure

    Public Enum ERRCODE
        Ok = 1
        NG = 2
        Err = 3
    End Enum

    ' 常量
    Public Const Cam_num As Integer = 3 '支持的相机数量

    Public G_AdminPwd As String
    Public Const Cam1_trig = 0 '相机1触发点位
    Public Const Cam2_trig = 1 '相机2触发点位
    Public Const Cam3_trig = 2 '相机3触发点位
    Public Const Cam4_trig = 3 '相机4触发点位
    Public Const Cam5_trig = 4 '相机4触发点位

    '系统参数
    Public strPassWord As String '登陆密码

    Public week As Integer '星期几
    Public gWarningMsg As String
    Public gIsModBus As Boolean
    Public gIsRun As Boolean '运行中表示
    Public gCheckIndex As Integer

    '统计值
    Public gTrigIndex As Integer

    Public gTotalNumCam(Cam_num - 1) As Integer '检测总数-每个相机单独统计
    Public gPassNumCam(Cam_num - 1) As Integer 'Pass数量-每个相机单独统计
    Public gTotalNum As Integer  '检测总数
    Public gPassNum As Integer  'Pass数量
    Public Check_SN As Boolean = False '扫条码变量

    '登陆参数
    Public gPriority As Integer '权限

    Public gEngineerPwd As String '工程师密码，默认123
    Public gAdminPwd As String '管理员密码，默认XC

    'io
    Public gIOCard As Integer 'IO卡编号

    Public Di_Data As Integer '当前输入值
    Public Di_Data_Last As Integer '上一次输入值，以便于当前输入值比较判断上升沿下降沿

    '图像处理参数
    Public fifo(Cam_num - 1) As CogAcqFifoTool '相机

    '  Public gTBPos(Cam_num - 1) As CogToolBlock '定位工具
    Public gTBCheck(Cam_num - 1) As CogToolBlock '检查工具

    Public gPosResult(Cam_num - 1) As offset '输出的XYR偏移量

    ' Public gComRecvData(Cam_num - 1) As String 'com口接收的数据
    '线程控制
    Public mut As New Threading.Mutex() '互斥事件，写入文件的互斥

    Public mutCount As New Threading.Mutex() '互斥事件，产品计数的互斥
    Public mutSp1 As New Threading.Mutex() '互斥事件，串口通讯的互斥
    Public mutSp2 As New Threading.Mutex() '互斥事件，串口通讯的互斥
    Public mutSp3 As New Threading.Mutex() '互斥事件，串口通讯的互斥
    Public mutSp4 As New Threading.Mutex() '互斥事件，串口通讯的互斥

    '产品参数
    Public gCurrProName As String

    Public gUserTime As Integer

    Public Checkbox_Disable(40) As System.Windows.Forms.CheckBox
    Public TextBox_Torq(40) As System.Windows.Forms.TextBox
    Public TextBox_Angle(40) As System.Windows.Forms.TextBox
    Public TextBox_feeder(40) As System.Windows.Forms.TextBox
    Public Checkbox_Round(40) As System.Windows.Forms.CheckBox

    Public PointPara(40) As Point_Para
    Public PointPass(30) As MITSUBISHI_Point
    Public PointWay(30) As Double
    Public Point_X轴C(30) As Double
    Public Point_Y轴C(30) As Double
    Public PointHigh(30) As Double

    '新增参数
    Public Debugpath As String = My.Application.Info.DirectoryPath

    Public CD_Dir As String = Application.StartupPath.Split("\")(0) & "\"
    Public gProDataPath As String = CD_Dir & "上位机资料\tool\"
    Public gVisionFailedPath As String

    Public UploadPath As String = My.Application.Info.DirectoryPath & "\数据上传程序"
    Public SoundPath As String = My.Application.Info.DirectoryPath & "\音频文件\"

    '与CCD相关
    Enum CCDRunStateInfo
        Nomal = 0
        SetError = 1 '设置序列号等错误
        Unconected = 2
        NoImage = 3 '连续两次未获取到图像
    End Enum

    ' Public FirstCCDSerNum As String = ""
    ' Public SecondCCDSerNum As String = ""

    Public FirstCCDState As Integer = 0
    Public SecondCCDState As Integer = 0

    Public ReceiveModbus(100) As Integer

    Public SendDataX(10) As Double
    Public SendDataY(10) As Double
    Public SendDataZ(10) As Double
    Public SendDataR(10) As Double

    Public Point_DateX(10) As Double
    Public Point_DateY(10) As Double
    Public Point_DateZ(10) As Double
    Public Point_DateR(10) As Double

    Public Chanpin As String
    Public Flag As String = "0"
    Public Flag_Alarm As String = ""
    Public Flag_YUYING As String = ""
    Public Flagshuju As String = ""
    Public Flag_robort As String = ""

    '与报警相关
    Public Structure AlarmInfo
        Public AlarmNum As String
        Public AlarmInformation As String
    End Structure

    Public AlarmObject As New ArrayList
    'Enum AlarmInfo
    '    Nomal = 0
    '    SetError = 1 '设置序列号等错误
    '    Unconected = 2
    '    NoImage = 3 '连续两次未获取到图像
    'End Enum

    Public Structure InputXY
        Public X01 As Double
        Public y01 As Double
        Public X02 As Double
        Public y02 As Double
        Public X03 As Double
        Public y03 As Double
        Public X04 As Double
        Public y04 As Double
        Public X05 As Double
        Public y05 As Double
        Public X06 As Double
        Public y06 As Double
        Public X07 As Double
        Public y07 As Double
        Public X08 As Double
        Public y08 As Double
        Public X09 As Double
        Public y09 As Double
        Public X0A As Double
        Public y0A As Double
        Public X0B As Double
        Public y0B As Double
        Public X0C As Double
        Public y0C As Double
        Public X0D As Double
        Public y0D As Double
        Public X0E As Double
        Public y0E As Double
        Public X0F As Double
        Public y0F As Double
        Public X0G As Double
        Public y0G As Double
        Public X0H As Double
        Public y0H As Double
        Public X0I As Double
        Public y0I As Double
        Public X0J As Double
        Public y0J As Double
        Public X0K As Double
        Public y0K As Double
        Public X0L As Double
        Public y0L As Double
        Public X0M As Double
        Public y0M As Double
        Public X0N As Double
        Public y0N As Double
        Public X0O As Double
        Public y0O As Double
        Public X0P As Double
        Public y0P As Double
        Public X0Q As Double
        Public y0Q As Double
        Public X0R As Double
        Public y0R As Double
        Public X0S As Double
        Public y0S As Double
        Public X0T As Double
        Public y0T As Double
        Public X0U As Double
        Public y0U As Double
        Public X0V As Double
        Public y0V As Double
        Public X0W As Double
        Public y0W As Double
        Public X0X As Double
        Public y0X As Double

        Public X11 As Double
        Public y11 As Double             '增加六个个数据
        Public X22 As Double
        Public y22 As Double
        Public X33 As Double
        Public y33 As Double
        Public X44 As Double
        Public y44 As Double
        Public X55 As Double
        Public y55 As Double
        Public X66 As Double
        Public y66 As Double

        Public Sub New(ByVal s() As Double)
            X01 = s(4)
            y01 = s(5)

            X03 = s(6)
            y03 = s(7)
            X04 = s(8)
            y04 = s(9)
            X05 = s(10)
            y05 = s(11)
            X06 = s(12)
            y06 = s(13)
            X07 = s(14)
            y07 = s(15)
            X08 = s(16)
            y08 = s(17)
            X09 = s(18)
            y09 = s(19)
            X0A = s(20)
            y0A = s(21)
            X0B = s(22)
            y0B = s(23)
            X0C = s(24)
            y0C = s(25)
            X0D = s(26)
            y0D = s(27)
            X0E = s(28)
            y0E = s(29)
            X0F = s(30)
            y0F = s(31)
            X0G = s(32)
            y0G = s(33)
            X0H = s(34)
            y0H = s(35)
            X0I = s(36)
            y0I = s(37)
            X0J = s(38)
            y0J = s(39)
            X0K = s(40)
            y0K = s(41)
            X0L = s(42)
            y0L = s(43)
            X0M = s(44)
            y0M = s(45)
            X0N = s(46)
            y0N = s(47)
            X0O = s(48)
            y0O = s(49)
            X0P = s(50)
            y0P = s(51)
            X0Q = s(52)
            y0Q = s(53)
            X0R = s(54)
            y0R = s(55)
            X0S = s(56)
            y0S = s(57)
            X0T = s(58)
            y0T = s(59)
            X0U = s(60)
            y0U = s(61)
            X0V = s(62)
            y0V = s(63)
            X0W = s(64)
            y0W = s(65)
            X0X = s(66)
            y0X = s(67)

            X11 = s(68)   '增加六个点位
            y11 = s(69)
            X22 = s(70)
            y22 = s(71)
            X33 = s(72)
            y33 = s(73)
            X44 = s(74)
            y44 = s(75)
            X55 = s(76)
            y55 = s(77)
            X66 = s(78)
            y66 = s(79)

        End Sub

    End Structure

    Public Structure AlarmSetting
        Public AlarmID As String '报警编号
        Public AlarmInfo As String '报警信息
        Public Alarmprocess As String '解决办法
    End Structure

    Public Structure Count
        Public PassCount As Integer '合格产品
        Public NGCount As Integer '识别失败
        Public SCount As Integer '打螺丝失败
        Public ScrewCount As Integer '锁付螺丝总数
        Public PCSFailedCount As Integer '失败台数
        Public CycleTime As Integer '制程时间
        Public SuctionCount As Integer '真空异常数
        Public ScanSN As Integer
        Public ScrewFailed1 As Integer
        Public ScrewFailed2 As Integer
        Public ScrewFailed3 As Integer
        Public ScrewFailed4 As Integer
        Public ScrewFailed5 As Integer
        Public ScrewFailed6 As Integer
        Public ScrewFailed7 As Integer
        Public ScrewFailed8 As Integer
        Public ScrewFailed9 As Integer
        Public ScrewFailed10 As Integer
        Public ScrewFailed11 As Integer
        Public ScrewFailed12 As Integer
        Public ScrewFailed13 As Integer
        Public ScrewFailed14 As Integer
        Public ScrewFailed15 As Integer
        Public ScrewFailed16 As Integer
        Public ScrewFailed17 As Integer
        Public ScrewFailed18 As Integer
        Public ScrewFailed19 As Integer
        Public ScrewFailed20 As Integer
        Public ScrewFailed21 As Integer
        Public ScrewFailed22 As Integer
        Public ScrewFailed23 As Integer
        Public ScrewFailed24 As Integer
        Public ScrewFailed25 As Integer
        Public ScrewFailed26 As Integer
        Public ScrewFailed27 As Integer
        Public ScrewFailed28 As Integer
        Public ScrewFailed29 As Integer
        Public ScrewFailed30 As Integer
        Public ScrewFailed31 As Integer
        Public ScrewFailed32 As Integer
        Public ScrewFailed33 As Integer
        Public ScrewFailed34 As Integer
        Public ScrewFailed35 As Integer
    End Structure

    Public Structure Count1
        Public SNCount As Integer '条码异常
        Public SN_Check As Integer '返回数据异常
    End Structure

    Public Structure ScrewPara
        Public PointCount As Integer '螺丝颗数
        Public ScrewSN As String '螺丝SN
        Public Online_Mod As Integer        '联机方式

        'Public High_set As Double '圈数测试设定值
        Public chuansong_yanshi As Double    '工具偏差

        'Public Z_set As Double 'Z轴高度测试设定值
        'Public Phone3_Pianyi As Double 'Phone3偏移设定值
    End Structure

    Public Structure returnXY
        Public X1 As Double
        Public Y1 As Double
        Public X2 As Double
        Public Y2 As Double
        Public X3 As Double
        Public Y3 As Double
        Public X4 As Double
        Public Y4 As Double
        Public X5 As Double
        Public Y5 As Double
        Public X6 As Double
        Public Y6 As Double
        Public X7 As Double
        Public Y7 As Double
        Public X8 As Double
        Public Y8 As Double
        Public X9 As Double
        Public Y9 As Double
        Public X10 As Double
        Public Y10 As Double
        Public X11 As Double
        Public Y11 As Double
        Public X12 As Double
        Public Y12 As Double
        Public X13 As Double
        Public Y13 As Double
        Public X14 As Double
        Public Y14 As Double
        Public X15 As Double
        Public Y15 As Double
        Public X16 As Double
        Public Y16 As Double
        Public X17 As Double
        Public Y17 As Double
        Public X18 As Double
        Public Y18 As Double
        Public X19 As Double
        Public Y19 As Double
        Public X20 As Double
        Public Y20 As Double
        Public X21 As Double
        Public Y21 As Double
        Public X22 As Double
        Public Y22 As Double
        Public X23 As Double
        Public Y23 As Double
        Public X24 As Double
        Public Y24 As Double
        Public X25 As Double
        Public Y25 As Double
        Public X26 As Double
        Public Y26 As Double
        Public X27 As Double
        Public Y27 As Double
        Public X28 As Double
        Public Y28 As Double
        Public X29 As Double
        Public Y29 As Double
        Public X30 As Double
        Public Y30 As Double

        Public X31 As Double                     '增加六个点位
        Public Y31 As Double
        Public X32 As Double
        Public Y32 As Double
        Public X33 As Double
        Public Y33 As Double
        Public X34 As Double
        Public Y34 As Double
        Public X35 As Double
        Public Y35 As Double
        Public X36 As Double
        Public Y36 As Double

        Public Function read() As String()
            Dim s(71) As String
            s(0) = X1
            s(1) = Y1
            s(2) = X2
            s(3) = Y2
            s(4) = X3
            s(5) = Y3
            s(6) = X4
            s(7) = Y4
            s(8) = X5
            s(9) = Y5
            s(10) = X6
            s(11) = Y6
            s(12) = X7
            s(13) = Y7
            s(14) = X8
            s(15) = Y8
            s(16) = X9
            s(17) = Y9
            s(18) = X10
            s(19) = Y10
            s(20) = X11
            s(21) = Y11
            s(22) = X12
            s(23) = Y12
            s(24) = X13
            s(25) = Y13
            s(26) = X14
            s(27) = Y14
            s(28) = X15
            s(29) = Y15
            s(30) = X16
            s(31) = Y16
            s(32) = X17
            s(33) = Y17
            s(34) = X18
            s(35) = Y18
            s(36) = X19
            s(37) = Y19
            s(38) = X20
            s(39) = Y20
            s(40) = X21
            s(41) = Y21
            s(42) = X22
            s(43) = Y22
            s(44) = X23
            s(45) = Y23
            s(46) = X24
            s(47) = Y24
            s(48) = X25
            s(49) = Y25
            s(50) = X26
            s(51) = Y26
            s(52) = X27
            s(53) = Y27
            s(54) = X28
            s(55) = Y28
            s(56) = X29
            s(57) = Y29
            s(58) = X30
            s(59) = Y30

            s(60) = X31      '增加6组数据
            s(61) = Y31
            s(62) = X32
            s(63) = Y32
            s(64) = X33
            s(65) = Y33
            s(66) = X34
            s(67) = Y34
            s(68) = X35
            s(69) = Y35
            s(70) = X36
            s(71) = Y36
            Return s
        End Function

        Public Sub New(ByVal s() As Double)
            X1 = s(0)
            Y1 = s(1)
            X2 = s(2)
            Y2 = s(3)
            X3 = s(4)
            Y3 = s(5)
            X4 = s(6)
            Y4 = s(7)
            X5 = s(8)
            Y5 = s(9)
            X6 = s(10)
            Y6 = s(11)
            X7 = s(12)
            Y7 = s(13)
            X8 = s(14)
            Y8 = s(15)
            X9 = s(16)
            Y9 = s(17)
            X10 = s(18)
            Y10 = s(19)
            X11 = s(20)
            Y11 = s(21)
            X12 = s(22)
            Y12 = s(23)
            X13 = s(24)
            Y13 = s(25)
            X14 = s(26)
            Y14 = s(27)
            X15 = s(28)
            Y15 = s(29)
            X16 = s(30)
            Y16 = s(31)
            X17 = s(32)
            Y17 = s(33)
            X18 = s(34)
            Y18 = s(35)
            X19 = s(36)
            Y19 = s(37)
            X20 = s(38)
            Y20 = s(39)
            X21 = s(40)
            Y21 = s(41)
            X22 = s(42)
            Y22 = s(43)
            X23 = s(44)
            Y23 = s(45)
            X24 = s(46)
            Y24 = s(47)
            X25 = s(48)
            Y25 = s(49)
            X26 = s(50)
            Y26 = s(51)
            X27 = s(52)
            Y27 = s(53)
            X28 = s(54)
            Y28 = s(55)
            X29 = s(56)
            Y29 = s(57)
            X30 = s(58)
            Y30 = s(59)

            X31 = s(60)
            Y31 = s(61)
            X32 = s(62)
            Y32 = s(63)
            X33 = s(64)
            Y33 = s(65)
            X34 = s(66)
            Y34 = s(67)
            X35 = s(68)
            Y35 = s(69)
            X36 = s(70)
            Y36 = s(71)
        End Sub

    End Structure

    Public Structure PsetSetting    '放置点补偿
        Public XPosCompensate As Double  'X补偿
        Public YPosCompensate As Double  'Y补偿
        Public ZPosCompensate As Double  'Z补偿
        Public RPosCompensate As Double  'R补偿
    End Structure

    Public Structure NameAndSN
        Public ChanpinName As String
        Public ChanpinSN As String
    End Structure

    Public Class SFCSByReal
        Public evt_type As String = "byreal"   '数据分类
        Public Plant As String  '厂别
        Public Dept As String   '车间
        Public Line As String '线别
        Public MachineName As String    'IP
        Public MachineModel As String '型号
        Public MachineSN As String  '设备名
        Public MachineNO As String    '设备NO
        Public MachineIP As String    '设备SN

        ' Public MachineKeyType As String  '扫码用KeyInfoType
        Public Time As Long

        Public Model As String
        Public Program As String
        Public Status As String
        Public Errcode As String
    End Class

    Public Class SFCSByPCS
        Public evt_type As String = "bypcs"  '数据分类
        Public Plant As String  '厂别
        Public Dept As String   '车间
        Public Line As String '线别
        Public MachineName As String    'IP
        Public MachineModel As String '型号
        Public MachineSN As String  '设备名
        Public MachineNO As String    '设备NO
        Public MachineIP As String    '设备SN

        ' Public MachineKeyType As String  '扫码用KeyInfoType
        Public Time As Long

        Public Program As String
        Public USN As String
        Public TotalPoint As Integer
        Public NGPoint As Integer
        Public SkipPoint As Integer
        Public SkipPointPICNO As String
        Public TotalInput As Integer
        Public OKInput As Integer
        Public NGInput As Integer
        Public YieldRate As Double
        Public OperatorID As String
        Public CameraoffsetX As Double
        Public CameraoffsetY As Double
        Public CameraoffsetUOM As String
        Public ScrewdriverSpeed As Double   '无
        Public ScrewdriverSpeedUOM As String = "r/min"
        Public AxisSpeedX As Double '无
        Public AcceTimeX As Double '无
        Public AxisSpeedY As Double '无
        Public AcceTimeY As Double '无
        Public AxisSpeedZ As Double '无
        Public AcceTimeZ As Double '无
        Public AxisSpeedUOM As String = "mm/s"
        Public AcceTimeUOM As String = "ms"
        Public StartTime As String
        Public EndTime As String
        Public CycleTime As Double
        Public Points() As PointData
        Public i As Integer

        Public Sub New(ByVal Size As UShort) 'Size就是传入的数组的大小
            Points = New PointData(Size) {}
            Dim i As Integer
            For i = 0 To Size
                Points(i).NGReson = "SCR-C0203"
            Next
        End Sub

        Public Structure PointData
            Public NO As Integer
            Public Result As String
            Public NGReson As String
            Public CCDCenterX1 As Double
            Public CCDCenterY1 As Double
            Public CCDCenterX2 As Double
            Public CCDCenterY2 As Double
            Public ScrewPositionX As Double
            Public ScrewPositionY As Double
            Public ScrewPositionZ As Double
            Public ScrewPositionR As Double
        End Structure

    End Class

    Public XY As InputXY
    Public Pset(40) As PsetSetting
    Public Pget(6) As PsetSetting
    Public myalarm(50) As AlarmSetting
    Public Todaycount As Count
    Public Todaycount1 As Count1

    Public Bfalge As Boolean = False
    Public SeverDate As String
    'new add for UpLoadData

    Public CurNameAndSN As NameAndSN    '已加载产品名及SN
    Public NewNameAndSN As NameAndSN    '新扫码产品名及SN
    Public DataByPCS As SFCSByPCS = New SFCSByPCS(35) '生产产品数据
    Public NullDataByPCS As SFCSByPCS = New SFCSByPCS(35) '生产产品数据0
    Public DataByReal As SFCSByReal = New SFCSByReal '实时上传数据
    Public NullDataByReal As SFCSByReal = New SFCSByReal '实时上传数据
    Public initOK_flag As Boolean = False '初始化完成flag
    Public UpLoadComplete_flag As Boolean = False '上传完成flag
    Public MachineInfo_flag As Boolean = True '设备信息加载完成flag

    Public MachineStatus As String  'Machine ON/OFF/Idel/Run/Shutdown
    Public MachineErrCode As String  'Machine Error Code,异常code
    Public CurScrewPara As ScrewPara
    Public ScrewOKCount As Integer    '设备螺丝总颗数
    Public CurPointNO As Integer    '当前数据螺丝号

    Public ZaxisPls(35) As Double    'Z相脉冲设定
    Public ZaxisCheckUSE As Boolean    '启用Z相检测
    Public ZaxisPl As Double
    Public GanAnle_Date(6) As Double    '枪头角度
    Public LineIP_Date(6) As String    ' 联机IP

    Public OldDataByReal As String = ""
    Public Suction As String

    '0:;1:;2:;3:;4:;5:;6:;7:;8:扫码功能;
    Public newset(9) As Boolean

    Public Selected As Integer = 0
    Public SPString As String = ""
    Public file_num_count As Integer = FreeFile()
    Public file_num_count1 As Integer = FreeFile()
    Public file_set As Integer = FreeFile()
    Public NumberOfAlarmArray As Integer
    Public NumberOfPSetArray As Integer = 30
    Public NumberOfSet As Integer = 14
    Public NumberOfGet As Integer = 4
    Public Input As String = ""
    Public SC_flag As String
    Public SN_Socket As Socket
    Public SecondRobotProduct As String = ""
    Public ThirdRobotProduct As String = ""
    Public FourthRobotProduct As String = ""
    Public SendProduct As String = ""
    Public NoProduct As Boolean = False
    Public Screw As String
    Public PATH_Xlsx As String = "Base_SN.xlsx"
    Public ADD_Screw_Count As Double
    Public Retry_Times As Double
    Public Clear_Time As Double
    Public DLLFirst As String
    Public DLLSecond As String
    Public Product_lenth As String
    Public SQL_Excel_Name1 As String
    Public SQL_Excel_Name2 As String
    Public PU_Name As String
    Public ScrewTime As String
    Public PicTime As String
    Public Angle As Short
    Public Angle1 As Double
    Public Angle2 As Double
    Public QuanShu1 As Double
    Public QuanShu2 As Double
    Public GanhanAngle As Double

    Public torque1 As Double
    Public Number_turns As Double
    Public cuowuleixing As Integer

    Public Torsion As Short
    Public Torsion1 As Double
    Public Torsion2 As Double

    Public RoundNum As Short
    Public RoundNum1 As Double
    Public RoundNum2 As Double
    Public RoundNum3 As Double
    Public No_Q As Boolean = False

    Public Upload_enable As Boolean

    Public RotationAngleo As Short
    Public RotationAngleo1 As Short

    Public RunningCCD As Boolean
    Public Ccd1AreaMinSet As Double
    Public Ccd1AreaMaxSet As Double

    Public Ccd2AreaMinSet As Double
    Public Ccd2AreaMaxSet As Double

    Public chanpin_zbx_X As Double
    Public chanpin_zbx_Y As Double
    Public chanpin_zbx_R As Double

    Public Chanpin_name As String

    Public Class MES51
        Public KPS As String
    End Class

    ''' <summary>
    ''' MES数据上传
    ''' </summary>
    Public Class BODY

        ''' <summary>
        ''' 线别 "LINE": "1ASSYA",
        ''' </summary>
        Public LINE As String

        ''' <summary>
        ''' 站别 "SECTION": "ASSY",
        ''' </summary>
        Public SECTION As String

        ''' <summary>
        ''' 工位，默认跟着段别来  "W_STATION": "ASSY_LBG",
        ''' </summary>
        Public W_STATION As String

        ''' <summary>
        ''' 不良，没不良给N/A "EC": "N/A",
        ''' </summary>
        Public EC As String

        ''' <summary>
        ''' "DATA": "SN",
        ''' </summary>
        Public DATA As String

        ''' <summary>
        ''' 站别 "MYGROUP": "TCONN"
        ''' </summary>
        Public MYGROUP As String

    End Class

    Public Class MesReturnData
        Public RetCode As String
        Public ErrCode As String
        Public ErrMsg As String
        Public Stack As String()
    End Class

    '数据上传
    Public Class IOT_Machine_Info    '设备信息
        Public Device_type As String  '设备的类型
        Public Manufacturer As String  '厂商
        Public Device_Code As String  '设备型号

        ''' <summary>
        ''' 机台号/站别
        ''' </summary>
        Public Device_id As String  '机台号/站别

        Public Line As String  '线别
        Public IP As String  'IP
        Public Family As String '机型

        Public IP_51 As String = "http://mesapi.lcfuturecenter.com:9000/api/gateway"

        ''' <summary>
        ''' 段别
        ''' </summary>
        Public SECTION As String '段别

        '
        Public MES_UploadAddress As String = "http://lmcp-service.lcfuturecenter.com/nbpec/framework-webproxy/proxy/"

        Public XEnv As String = ""
        Public Token As String = "eyJ1c2VySWQiOiJtZXMtZTYwNzYwMzRkMTFiYzNhOTllNThkZTcxYjlkIiwidXNlck5hbWUiOiJoaWNhZG1pbkBsY2ZjLmNvbSIsImVudiI6InFhcyIsImZhY3RvcnlJZCI6bnVsbCwicm9sZXMiOltdLCJ0ZW5hbnRJZCI6bnVsbCwiQWxpYXMiOiJoaWNhZG1pbkBsY2ZjLmNvb"
        Public UserName As String = "mestest"
        Public DirSwitchProd As String

        '
        Public ScanStrartString As String

        Public ScanSnLength As String

        ''' <summary>
        ''' 第一台清空所有队列
        ''' </summary>
        Public FirstClearQuene As String = "0"

        ''' <summary>
        ''' 清空所有队列
        ''' </summary>
        Public ClearQuene As String = "0"

        ''' <summary>
        ''' 参数设置必须登录
        ''' </summary>
        Public ConfigMustLogin As String = "1"

    End Class

    Public Class IOT_Machine_Status                 'Timer2_Tick  定时器更新数据
        Inherits IOT_Machine_Info
        Public Status As String  '状态  0运行 1 等待 2 宕机 3 XCPro开机  4 XCPro关机
        Public ErrorCode As String  '错误代码
        Public CreateTime As String
        Public UpdateTime As String
    End Class

    Public Class IOT_FILATURE_MainInfo    '设备生产总的主要信息  （现在没有用  UploadMainInfo_Tick定时器）
        Inherits IOT_Machine_Info
        Public NoteBook_Qty As String  '笔记本数
        Public Screw_Qty As String  '总螺丝数
        Public SF_Fail_Qty As String  '锁附异常总数
        Public SB_Fail_Qty As String  '识别异常总数
        Public Yield As String  '良率
        Public RunTime As String  '开机时间
        Public SF_Time As String  '锁附总时长
        Public IDEL As String  'IDEL总时长
        Public UpdateTime As String
    End Class

    Public Class IOT_FILATURE_SN_Info    '生产一台的生产信息
        Inherits IOT_Machine_Info
        Public Family2 As String  '机型
        Public SN As String  'SN
        Public SF_Cdt_Begin As String  '锁附开始时间
        Public SF_Cdt_End As String  '锁附结束时间
        Public Screw_Qty As String  '锁附螺丝数
        Public SF_Fail_Qty As String  '锁附异常数
        Public SB_Fail_Qty As String  '识别异常数
        Public Status As String  '状态（PASS/RPASS/Fail）
    End Class

    Public Class OPC_ProcessingDetails
        Public SN As String  'SN
        Public objs() As OPC_OnePcsDetails

        Public Sub New()
            Me.SN = ""
        End Sub

        Public Sub New(ByVal N As Integer)
            ReDim objs(N)
            For i As Integer = 0 To N - 1
                Me.objs(i) = New OPC_OnePcsDetails
            Next
        End Sub

    End Class

    Public Class OPC_OnePcsDetails
        Public TorqueValue As String  '扭力值
        Public Status As String  '状态（PASS/FAIL）
        Public ErrType As String  '异常代码
        Public StartTime As DateTime  '锁附开始时间
        Public EndTime As DateTime  '锁附结束时间
        Public UsedTime As Double  '锁附时间
        Public NumOfScrew As String '第几颗螺丝
        Public SpecTime As String '规定时间
    End Class

    Public Class IOT_FILATURE_SN_Detail    '锁付一颗的信息
        Public SN As String  'SN
        Public Screw_A1 As String  '锁附坐标值
        Public TorqueValue As String  '扭力值
        Public Status As String  '状态（PASS/FAIL）
        Public ErrType As String  '异常代码
        Public SF_Cdt_Begin As DateTime  '锁附开始时间
        Public SF_Cdt_End As DateTime  '锁附结束时间
        Public NumOfScrew As String '第几颗螺丝
    End Class

    Public EquipmentInfo As IOT_EquipmentInfo = New IOT_EquipmentInfo

    Public Structure IOT_EquipmentInfo    '设备管理信息
        Public Robot_Company As String
        Public Robot_Version As String
        Public Robot_Datatime As String
        Public Charge_Name As String
        Public Charge_Telephone As String
        Public Charge_Email As String
        Public OPCVersion As String
        Public SoftVersion As String
        Public MachineID As String
        Public LineID As String
        Public StationID As String
    End Structure

    Public machineInfo As IOT_Machine_Info = New IOT_Machine_Info '设备信息
    Public machineInfoStatus As IOT_Machine_Status = New IOT_Machine_Status '设备状态信息
    Public mainInfo As IOT_FILATURE_MainInfo = New IOT_FILATURE_MainInfo '设备生产总数据信息
    Public SNInfo As IOT_FILATURE_SN_Info = New IOT_FILATURE_SN_Info '生产一台的生产信息

    Public processingDetails As New OPC_ProcessingDetails(2)
    Public onePcsDetailsQueue As New Queue(Of OPC_OnePcsDetails)
    Public curPcsDetails As New OPC_OnePcsDetails

    Public HistoryStatus As ArrayList = New ArrayList '历史上传状态信息
    Public Tcmb_Queue As Queue = New Queue '产品队列
    Public SN_Queue As Queue = New Queue 'SN队列

    Friend WithEvents TCmbPro As System.Windows.Forms.ToolStripComboBox

    Public MySQLIP As String = "" '数据库IP
    Public MySQLUserName As String = "" '数据库登录用户名
    Public MySQLPassWord As String = "" '密码
    Public MySQLDataBase As String = "" '数据库名称

    '
    Public MySQLIPRemote As String = "" '数据库IP

    Public MySQLUserNameRemote As String = "" '数据库登录用户名
    Public MySQLPassWordRemote As String = "" '密码
    Public MySQLDataBaseRemote As String = "" '数据库名称

    '
    Public FTPUploadPath1 As String = ""

    Public StateFreTime As String = "" '状态上传频率
    Public ProductFreTime As String = "" '生产数据上传频率
    Public startTime As DateTime = DateTime.MinValue
    Public startTime_SC As DateTime = DateTime.MinValue
    Public endTime As DateTime = DateTime.MinValue
    Public SF_Fail_Qty_Single As Integer = 0                     '锁付一台的失败颗数
    Public SB_Fail_Qty_Single As Integer = 0                     '视觉失败=1 视觉成功=0
    Public shutDownTime As Double = 0 '异常时间
    Public startTime_SD As DateTime = DateTime.MinValue
    Public endTime_SD As DateTime = DateTime.MinValue
    Public line As String = "" '参数设置line站号
    Public keycode As String = "" '参数设置keycode
    Public Paramset_num As Integer = FreeFile()

    Public Receive_MesSN() As String
    Public Receive_MesMSG() As String
    Public Receive_MesMODELID() As String

    Public SN_Screw_Info As ArrayList = New ArrayList()
    Public VisionFlag As Boolean = False

    Public Class ScrewPoint
        Public ScrewX As Double
        Public ScrewY As Double
        Public ScrewZ As Double
        Public ScrewU As Double
    End Class

    '新增加的方法
    Public sphelper As SerialPortHelper

    Public socket As SocketHelper = New SocketHelper                 '网口1  连接机器人 plc
    Public socketIOT As SocketHelper = New SocketHelper                 '网口IOT 数据上传程序
    Public log As LogHelper
    Public socket2 As SocketHelper = New SocketHelper                '网口2  机台之间数据交互
    Public socket3 As SocketHelper = New SocketHelper                 '扫码枪

    Public StepNO As String = "SETP0"
    Public AutoAddPhotoPoint(3) As MITSUBISHI_Point
    Public StepOK1 As Boolean
    Public StepOK2 As Boolean
    Public StepOK3 As Boolean
    Public Vision_NG As String

    Public Structure MITSUBISHI_Point
        Public X As Double
        Public Y As Double
        Public Z As Double
        Public A As Double
        Public B As Double
        Public C As Double
        Public L1 As Integer
        Public L2 As Integer
        Public FLG1 As Integer '左右手姿态
        Public FLG2 As Integer

        Public Function PtoString()
            Dim str1 As String
            str1 = "(" & X & "," & Y & "," & Z & "," & A & "," & B & "," & C & "," & L1 & "," & L2 & ")(" & FLG1 & "," & FLG2 & ")"
            Return str1
        End Function

    End Structure

    Public Motor_flag As Boolean '机器人伺服启用标志
    Public AddProdflag As Boolean = False
    Public Globalfunc As FuncPortal.FuncLNLON = New FuncPortal.FuncLNLON
    Public RunQFlag As String
    Public RunQSocket As Socket
    Public Open_time As Integer  '软体开启时间
    Public Run_time As Integer
    Public OpenRT_Time As Integer
    Public PLCdate(30) As Double

    Public SoveProdLuck As Boolean
    Public SoveProdCP As Boolean
    Public Prod_Stade As String
    Public time_Screw As String

    Public LogRed As Boolean

    Public Lucktorque(30) As Double          '单颗锁附扭力数组
    Public LucktQS(30) As Double          '单颗锁附圈数数组
    Public Luckttime(30) As String           '单颗锁附时间数组
    Public LuckState(30) As String           '单颗锁附OK/NG

    Public GetAngle As Double                '取料角度
    Public Revedateq As Boolean = True               '前一台给的产品OK/NG信息

    ''' <summary>
    ''' '保养信息
    ''' </summary>
    ''' <remarks></remarks>
    Public MaintainInfo As IOT_MaintainInfo = New IOT_MaintainInfo

    Public Structure IOT_MaintainInfo    '保养管理信息

        '1.供料器保养
        Public Feeder_Status As Integer

        Public Feeder_preMaintanceTime As String
        Public Feeder_MaintanceCycle As Integer

        '2.整机清洁保养
        Public Clean_Status As Integer

        Public Clean_preMaintanceTime As String
        Public Clean_MaintanceCycle As Integer

        '3.皮带保养
        Public Blet_preMaintanceTime As String

        Public Blet_Status As Integer
        Public Blet_MaintanceCycle As Integer

        '4.线缆接头保养
        Public Cable_preMaintanceTime As String

        Public Cable_Status As Integer
        Public Cable_MaintanceCycle As Integer

        '5.电机
        Public Motor_preMaintanceTime As String

        Public Motor_Status As Integer
        Public Motor_MaintanceCycle As Integer

        '6.机器人保养
        Public Robot_preMaintanceTime As String

        Public Robot_Status As Integer
        Public Robot_MaintanceCycle As Integer

        '7.螺丝松动保养
        Public Screw_preMaintanceTime As String

        Public Screw_Status As Integer
        Public Screw_MaintanceCycle As Integer

        '8.起子头保养
        Public Screwdriver_preMaintanceTime As String

        Public Screwdriver_Status As Integer
        Public Screwdriver_MaintanceCycle As Integer

        '9.吸嘴保养
        Public Nozzle_preMaintanceTime As String

        Public Nozzle_Status As Integer
        Public Nozzle_MaintanceCycle As Integer
    End Structure

    Public MaintanceSearchFlag As Integer = 0
    Public Erro_Msg As String = ""
    Public Mes_msg As String = ""
    Public MesNewPro As String = ""
    Public MesProStatus As String
    Public ReciveMsg As String = ""
    Public ReciveErro As String = ""
    Public RobotStation As Integer
    Public ScrewDnum As Integer

    'OPC上传对象
    Public OPC_Machine_Parameter As ScrewMachine_Parameter = New ScrewMachine_Parameter

    Public OPC_Machine_Sensor As ScrewMachine_Sensor = New ScrewMachine_Sensor
    Public OPC_Machine_ProductionData As ScrewMachine_ProductionData = New ScrewMachine_ProductionData
    Public OPC_Machine_Status As ScrewMachine_Status = New ScrewMachine_Status
    Public OPC_Machine_Info As ScrewMachine_Info = New ScrewMachine_Info
    Public OPC_Machine_Maintance As ScrewMachine_Maintance = New ScrewMachine_Maintance
    Public OPC_Machine_Alarm As Alarm_Status = New Alarm_Status
    Public OPC_Machine_ProductionLog As ScrewMachine_ProductionLog = New ScrewMachine_ProductionLog
    Public OPC_Machine_AddScrew As ScrewMachine_AddScrew = New ScrewMachine_AddScrew
    Public OPC_AddScrewRemind As Boolean = False

    Public EQ_Status As Integer

    Enum Equipment_Status
        _STARTUP = 0
        _RUN = 1
        _PAUSE = 2
        _EMERGENCY = 3
        _ALARM = 4
        _MAINTANCE = 5
    End Enum

    Public gjson As New JsonHelper
    Public KeyPartPassTXT As String '"SN,SN$NO1,NO2$"
    Public unLockNO(3) As Integer

    Public Enum RobotConnectType

        ''' <summary>
        ''' 短连接
        ''' </summary>
        Shortlink = 0

        ''' <summary>
        ''' 长连接
        ''' </summary>
        LongConnection = 1

    End Enum

End Module